package resman.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.hibernate.Session;

import resman.bean.ResumeBean;
import resman.database.DatabaseHandler;
import resman.database.TransSession;
import resman.model.ActionServlet;

@SuppressWarnings("serial")
@WebServlet("/SearchServlet")
public class SearchServlet extends ActionServlet
{
	
	@Override
	protected void process(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException
	{
		String name = getParameter("name", request).toLowerCase();
		TransSession tsession = DatabaseHandler.openSession(true);
		Session session = tsession.getSession();
		
		@SuppressWarnings("unchecked")
		List<ResumeBean> result = (List<ResumeBean>)session.createQuery("from ResumeBean " +
				"where personal.name like '%" + name + "%'")
				.list();

		getSession(request).setAttribute("result", result);
		
		tsession.close();
		dispatchTo("views/result_view.jsp", request, response);
	}

}
